﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UDS.Entity;
using UDS.Web;

namespace UDS.WebApp.SubModule
{
    public partial class DownloadPersonalFilePage : Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            int fileId = QSUtil.GetPositiveInt32("fileId");
            if (fileId > 0)
            {
                PFFileInfo fileInfo = PFFileInfo.GetFileInfo(SiteContext.Current.UserID, fileId);
                if (fileInfo != null)
                {
                    string physicalPath = HttpUtil.MapPath(fileInfo.VPath);
                    if (System.IO.File.Exists(physicalPath))
                    {
                        var response = new HttpFileResponse(Context, physicalPath);
                        response.OutputName = fileInfo.Name;
                        response.ProcessRequest();
                        return;
                    }
                }
            }

            SiteContext.Current.Alert("指定的文件不存在。", true);
        }
    }
}
